package com.aws.one;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ListObjectsV2Request;
import com.amazonaws.services.s3.model.ListObjectsV2Result;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2024/1/15 - 16:59
 */
@Component
public class ListDemo {

    @Autowired
    AmazonS3 amazonS3;

    public void list(){

        ListObjectsV2Request req = new ListObjectsV2Request().withBucketName("mylibugu").withMaxKeys(2);
        ListObjectsV2Result result;

        do{
            result = amazonS3.listObjectsV2(req);
            for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
                System.out.printf(" - %s (size : %d)\n",objectSummary.getKey(),objectSummary.getSize());
            }
            String nextContinuationToken = result.getNextContinuationToken();
            System.out.println("next token================="+nextContinuationToken);
            req.setContinuationToken(nextContinuationToken);
        }while (result.isTruncated());
    }

}
